﻿package  {
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.text.TextField;
	import flash.geom.Matrix;
	
	public class Obstacle extends Bitmap {		
		
		public static const HAZARD:int = 1;
		public static const COIN:int = 2;
		
		private var type:int;
		private var screenWidth:int;		

		public function Obstacle(controller:ObstacleController, bitmapData:BitmapData, runningGame:RunningGame) {
			this.bitmapData = bitmapData;
			this.screenWidth = runningGame.getScreenWidth();
			this.x = Math.floor(Math.random() * screenWidth);
			this.y = -this.height;			
			
			if(bitmapData is Hazard1BD) {
				this.type = HAZARD;	
			}else if(bitmapData is CoinBD) {
				this.type = COIN;							
			}
		}
		
		public function moveDown(speed:Number) {
			this.y += speed;
		}
		
		public function resetPosition() {
			this.x = Math.floor(Math.random() * screenWidth - this.width);			
			this.y = -this.height;
		}
		
		public function intersect(x:Number, y:Number, width:Number, height:Number) {
			return (this.x + this.width >= x && this.x <= x+width && this.y + this.height >= y && this.y <= y+height);
		}
		
		public function getType() {
			return type;
		}
	}
	
}
